//
// Created by hkkzzxz on 24-8-31.
//

#include "Config.h"
#include "LogManager.h"
#include "UnderlyingServer.h"

#include <iostream>


void Config::start(int port_) {
    port = port_;

    printSoul();
    // 初始化日志库
    initLog();
    // 启动服务器
    startServer();
}

void Config::printSoul() {
    //打印有趣的灵魂
    std::cout << "--------------Designed by YunShi-Team--------------\n";
    std::cout << "----y----------y-----------------------s-s-s-------\n";
    std::cout << "------y------y-----------------------s-------s-----\n";
    std::cout << "---------y-y----------------------------s----------\n";
    std::cout << "----------y--------------------------------s-------\n";
    std::cout << "----------y-----------------------------------s----\n";
    std::cout << "----------y---------------------------s--s-s-------\n";
    std::cout << "---------------------------------------------------\n";
    std::cout << "\n";
}

void Config::initLog() {
    try {
        auto *logManager = LogManager::getInstance();

        // 初始化日志系统
        logManager->init("logs/app_log.txt", spdlog::level::debug);

        // 获取控制台日志器
        auto consoleLogger = logManager->getConsoleLogger();

        //获取文件日志器
        auto fileLogger = logManager->getFileLogger();

        // 使用控制台日志器记录信息
        consoleLogger->info("Log initialization was successful");

        //使用文件日志器记录信息
        fileLogger->info("Log initialization was successful");
    }
    catch (const std::exception &e) {
        std::cerr << "Log initialization failed" << e.what() << "\n";
    }
}


void Config::startServer() {
    auto server = std::make_unique<UnderlyingServer>();
    server->start(port);
}


